<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1.0" />
    <title>
    <#if czjroulette.ext2 ?? && czjroulette.ext2 =="1">
                 线上转盘详情
    <#else>
                线下转盘详情
    </#if>
    </title>
    <#include "/view/admin/head.html"/>

    <style type="text/css">
        .list-path{
            height: 50px;
            line-height: 50px;
            background-color: #9acfea;

        }
        .table-class{
            width:80%;
            text-align: center;
            border:1px solid #afd9ee;
            margin:0 auto;
            margin-top: 50px;
        }
        table th{
            background-color: #d9edf7;
            text-align: left;
        }
        td{   
            width:20%;         
            background-color: #d9edf7;
            text-align: left;
        }
        .go-back{
            float:right;
            margin-right: 30px;

        }
    </style>

<script type="text/javascript">
function firstFileImg(obj) {
		//input
		var docObj = obj;
		//img
		var imgObjPreview = docObj.nextSibling.nextSibling;
		//div
		var divs = document.getElementById("localImag");
		if (docObj.files && docObj.files[0]) {
			//火狐下，直接设img属性
			imgObjPreview.style.width = '242px';
			imgObjPreview.style.height = '170px';
			//imgObjPreview.src = docObj.files[0].getAsDataURL();
			//火狐7以上版本不能用上面的getAsDataURL()方式获取，需要一下方式
			imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]);
		} else {
			//IE下，使用滤镜
			docObj.select();
			var imgSrc = document.selection.createRange().text;
			var localImagId = document.getElementById("localImag");
			//必须设置初始大小
			localImagId.style.width = "242px";
			localImagId.style.height = "170px";
			//图片异常的捕捉，防止用户修改后缀来伪造图片
			try {
				localImagId.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
				localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
			} catch(e) {
				alert("您上传的图片格式不正确，请重新选择!");
				return false;
			}
			
			imgObjPreview.style.display = 'none';
			
			document.selection.empty();
		}
		return true;
	}  

function secondFileImg(obj) {
	//input
	var docObj = obj;
	//img
	var imgObjPreview = docObj.nextSibling.nextSibling;
	//div
	var divs = document.getElementById("localImag");
	if (docObj.files && docObj.files[0]) {
		//火狐下，直接设img属性
		imgObjPreview.style.width = '242px';
		imgObjPreview.style.height = '170px';
		//imgObjPreview.src = docObj.files[0].getAsDataURL();
		//火狐7以上版本不能用上面的getAsDataURL()方式获取，需要一下方式
		imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]);
	} else {
		//IE下，使用滤镜
		docObj.select();
		var imgSrc = document.selection.createRange().text;
		var localImagId = document.getElementById("localImag");
		//必须设置初始大小
		localImagId.style.width = "242px";
		localImagId.style.height = "170px";
		//图片异常的捕捉，防止用户修改后缀来伪造图片
		try {
			localImagId.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
			localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
		} catch(e) {
			alert("您上传的图片格式不正确，请重新选择!");
			return false;
		}
		
		imgObjPreview.style.display = 'none';
		
		document.selection.empty();
	}
	return true;
}  

function thirdFileImg() {
	//input
	var docObj = document.getElementById("thirdFile");
	//img
	var imgObjPreview = document.getElementById("thirdImg");
	//div
	var divs = document.getElementById("localImag");
	if (docObj.files && docObj.files[0]) {
		//火狐下，直接设img属性
		imgObjPreview.style.width = '242px';
		imgObjPreview.style.height = '170px';
		//imgObjPreview.src = docObj.files[0].getAsDataURL();
		//火狐7以上版本不能用上面的getAsDataURL()方式获取，需要一下方式
		imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]);
	} else {
		//IE下，使用滤镜
		docObj.select();
		var imgSrc = document.selection.createRange().text;
		var localImagId = document.getElementById("localImag");
		//必须设置初始大小
		localImagId.style.width = "242px";
		localImagId.style.height = "170px";
		//图片异常的捕捉，防止用户修改后缀来伪造图片
		try {
			localImagId.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
			localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
		} catch(e) {
			alert("您上传的图片格式不正确，请重新选择!");
			return false;
		}
		
		imgObjPreview.style.display = 'none';
		
		document.selection.empty();
	}
	return true;
}  


</script>    
    
</head>
<body>

<div class="list-path" > <span style="margin-left: 50px;"><span class="glyphicon glyphicon-home"></span> 
    <#if czjroulette.ext2 ?? && czjroulette.ext2 =="1">
                 转盘奖品编辑
    <#else>
                转盘奖品编辑
    </#if>
     </span></div>
    <#if czjroulette.ext2 ?? && czjroulette.ext2 =="1">
<!--         <div style="float:right;margin-right: 40px;"><a class="btn btn-info" href="${base}/roulette/czjrouletteList.do">返回上一级</a></div> -->
    <#else>
<!--         <div style="float:right;margin-right: 40px;"><a class="btn btn-info" href="${base}/roulette/czjrouletteoffList.do">返回上一级</a></div> -->
    </#if>
</div>



<div class="table-class">       
      <#if  message?? &&  message =="1" >
        <div class="alert alert-error" style="background-color: write;color: green;">           
           <font size="5"><strong>发布成功</strong></font>
        </div>
     </#if>
      <#if  message?? &&  message =="0" >
        <div class="alert alert-error" style="background-color: write;color: red;">           
           <font size="5"><strong>取消发布</strong></font>
        </div>
     </#if>
      <#if  message?? &&  message =="3" >
        <div class="alert alert-error" style="background-color: write;color: red;">           
           <font size="5"><strong>添加奖品后,才能发布</strong></font>
        </div>
     </#if>     
      <#if  message?? &&  message =="2" >
        <div class="alert alert-error" style="background-color: write;color: green;">           
           <font size="5"><strong>保存转盘信息成功</strong></font>
        </div>
     </#if>     
      
    <table class="table table-bordered">
        <tbody>
          <form  action="${base}/roulette/czjawardSave.do?rouletteId=${czjroulette.rouletteId!}" method="post" enctype="multipart/form-data"   id="myform" >
               <input  type="hidden" name="ext2" value="${czjroulette.ext2!}"/>
                  
               <tr>
                <th>活动名称：</th>
                <td> 
                ${czjroulette.actname!}                                             
                </td>
                <th>活动开始时间：</th>
                <td> 
                  <#if (czjroulette.starttime)??>${czjroulette.starttime?string('yyyy-MM-dd')} </#if>                                                                     
                </td>
                <td></td><td></td><td></td>
              </tr>
               <tr>
                <th>活动结束时间：</th>
                <td><#if (czjroulette.endtime)??>${czjroulette.endtime?string('yyyy-MM-dd')} </#if>                                                
                </td>
                <th>活动地点：</th>
                <td> 
                ${czjroulette.place!}                                                                      
                </td>
                <td></td><td></td><td></td>
              </tr>
               <tr>
                <th>活动说明：</th>
                <td>${czjroulette.content!}</td>                                                
                </td>
                <th>活动类型：</th>
                <td> 
		    <#if czjroulette.actType?? && czjroulette.actType == 1 > 转盘活动</#if> 
	    	<#if czjroulette.actType?? && czjroulette.actType == 2 > 二维码活动</#if> 
                                                                  
                </td>
                <td></td><td></td><td></td>
              </tr> 
                 <tr>
                <th>转盘名称：</th>
                <td>${czjroulette.remark!} </td>                                                
                </td>
                <th>转盘分多少等份：</th>
                <td> 
                  ${czjroulette.ext3!}                                                                       
                </td>
                <td></td><td></td><td></td>
              </tr>
               <tr>
                <th>抽奖说明：</th>
                <td>${czjroulette.roulettecontent!}                                                 
                </td>
                <th></th>
                <td></td><td></td><td></td><td></td>                
              </tr>                         
              <tr>
                <th >预览转盘背景图片：</th>
                <td ><img src="${base}${czjroulette.imgPath!}" height="100px;" id="firstImg"></td>
                <th >预览转盘指针图片：</th>
                <td ><img src="${base}${czjroulette.imgUrl!}" height="100px;" id="secondImg"></td>
                <td></td><td></td><td></td>
              </tr>                         
   
			<tr >
			<th>奖品序号</th>
			<th>选择奖品</th>
			<th>奖品概率</th>
			<th>奖品数量</th>
			<th>扫码领取</th>
			<th>中奖说明</th>
			<th>中奖补充说明</th>			
			</tr>
                                                       
          <#if czjroulette.rouletteId ??>   
            <#list czjawardonVORs as c>
              <tr>
                <td > 
                 ${c.ext1!html}
                </td> 
                <td >
                     <#list czjawardstocks as d>
                        <#if c.thingId?? && c.thingId == d.awardstockId > ${d.thingName!?html}</#if> 
                     </#list>                                   
                </td>  
               	<td >
                    ${c.probability!}
                </td>
                <td >
                   ${c.count!}
                </td>
                <td >
					 <#if c.theme?? && c.theme=="1" >否 </#if>
					 <#if c.theme?? && c.theme=="2" >否 </#if>
					 <#if c.theme?? && c.theme=="3" >是 </#if>
					 <#if c.theme?? && c.theme=="4" >否 </#if>  
					 <#if c.theme?? && c.theme=="5" >否 </#if>  
					 <#if c.theme?? && c.theme=="6" >否 </#if>                   
                </td>
                <td >
                  <img src="${base}${c.prizePath!}"  width="60px" height="100px;" >                           
                </td>
                <td >
                  <img src="${base}${c.backgroundPath!}" width="60px" height="100px;"  >                           
                </td>                                                                                      
              </tr>                            
            </#list>                      
          </#if>       
            
               
 
              

              

     </form>   

       <tr>
            <td colspan="4" width="100%" style="text-align: center;">
            
              <a class="btn btn-success  approve-btn btn-approve" href="czjrouletteActList.do">&nbsp;返回&nbsp;</a>
                <span >&nbsp;</span>               
            </td>
            <td></td><td></td><td></td>
        </tr>
               
        </tbody>
    </table>

</div>

<script type="text/javascript">

function thingIdsSel(obj){
	var discountShop = obj.value;
    //获取当前的奖品库数量
    var  shengyunum = shengyunum1(discountShop);
   	   
   var tdnum =  obj.parentNode.parentNode.children[3];
   
   $(tdnum).children().val(shengyunum);

   var inputIndex = obj.parentNode.children[1];
   $(inputIndex).val(1);
   var nameIndex = obj.parentNode.children[2]; 
   $(nameIndex).val($(obj).find("option:selected").text());
   var idIndex = obj.parentNode.children[3];
   $(idIndex).val(obj.value); 
} 

/* //onchange 选择时间
function thingIdsSel(obj){
		var discountShop = obj.value;
        //获取当前的奖品库数量
        var  shengyunum = shengyunum1(discountShop);
        //获取所有Id的元素        
 	   var thingIds =$("select[name='thingIds']");	   	  	    
 	  //当前页面还能分配多少
 	  var totalnum = 0; 	  
	   //计算自己分配的值
	   var thisnum2 =  obj.parentNode.parentNode.children[3];
	   //自己的值
	   var mynum = $(thisnum2).children().val();
	   if(mynum ==""){
		   mynum = 0;
	   }   

	   thingIds.each(function(){
		   //这里的值
           var thisvalue = this.value;  	   
		   //这里的值等于选择的值时候
		   if(thisvalue == discountShop ){
			   var abc =  this.parentNode.parentNode.children[3];		   
			   var eachnum = $(abc).children().val();
			   if(eachnum ==""){
				   eachnum = 0;
			   } 
			   totalnum = eval(totalnum) + eval(eachnum) ;
		   }
		
	   }); 
	   
	   shengyunum = eval(shengyunum) - eval(totalnum) + eval(mynum);
	   	   
	   var tdnum =  obj.parentNode.parentNode.children[3];
	   
	   $(tdnum).children().val(shengyunum);
	
  
} */

function shengyunum1(obj){
	var  shengyunum ="";
    $.ajax({  
        type : "post",  //提交方式  
        url : "czjthingId.do",//路径  
        async: false,
        data : "discountShop="+obj,//数据，这里使用的是Json格式进行传输      
        dataType: "json",
        success : function(result) {//返回数据根据结果进行相应的处理  
	     
        shengyunum =  result.result.shengyunum;
        
        if(shengyunum==null){
        	shengyunum = 0;
        }
        
        }
    });  
	return shengyunum;
}



var thingIdALL = $("#thingIdALL option");

function addAward(){

	 $("#addAwardTr").after(
              "<tr>"
             +"<th >请选择奖品：</th>"
             +"<td >"
             +"<select name='thingIds' ><select>"
             +"</td>"
             +"<th >奖品数量：</th>"
             +"<td >"                            
             +"</td>"
           +"</tr>"
           +"<tr>"
             +"<th >设置奖品概率：</th>"
             +"<td >"
             +"<input type='text' name='probabilitys'value=''>" 
             +"</td>"
             +"<th >分配这个奖品数量：</th>"
             +"<td >" 
             +"<input type='text' name='countnums'  value='0'>"              
             +"</td>"
           +"</tr>" 			 
            +"<tr>"
            +"<th >已经抽取的数量：</th>"
            + "<td >"
             +"<input  name='ext2s' value='0' >"                                   
             +"</td>"
             +"<th >奖品顺序：</th>"
             +"<td >"
             +"<input  name='ext1s' value='0' >" 
             +"<input type='button' class='btn btn-primary'  value='删除奖品' onclick='delPlace(this);'/>"
             +"</td>" 
           +"</tr>" 	 
	 );
      
	 var thingIds = $("select[name='thingIds']");
	 	  
	  for(var i=0; i<thingIdALL.length;i++){
			 thingIds.append(
			 "<option value='"+thingIdALL[i].value+"'>"+thingIdALL[i].text+"</option>"		 
			 );
		  
	  }
	 

	 
	 
}


function delPlace(obj){		
	obj.parentNode.parentNode.previousSibling.previousSibling.remove();
	obj.parentNode.parentNode.previousSibling.remove();
	obj.parentNode.parentNode.remove();
} 
  
function delPlace1(obj){
	obj.parentNode.parentNode.previousSibling.previousSibling.remove();
	obj.parentNode.parentNode.previousSibling.remove();
	obj.parentNode.parentNode.remove();
}
   //不发布
  function notRelease(){
	  location.href="${base}/roulette/czjrouletteSaveExt1.do?rouletteId=${czjroulette.rouletteId!}&ext1=0";
  }

  //发布
  function release(){
	  location.href="${base}/roulette/czjrouletteSaveExt1.do?rouletteId=${czjroulette.rouletteId!}&ext1=1";
  }

  //提交图片
  function submitVoteOrder(){
	  
	  var thingIds1 =$("select[name='thingIds']");
	  
	  thingIds1.each(function(){
		  alert(this);
	  });
	  	  	  	  	  	             	
	   var probabilitys = $("input[name='probabilitys']");
	   
	   var num = 0;
	   probabilitys.each(function(){
		   num = eval(num) + eval(this.value);
	   });
	   if(num !=1 ){
		   alert("概率之和必须等于1");
		   return;
	   }
	   	   	      
	   var thingIds =$("select[name='thingIds']");
	   var thingIdsindex = false;
	   thingIds.each(function(){
		   if(this.value==-1){
			   thingIdsindex =true;			  
		   }		   
	   });	  
	   
	   if(thingIdsindex){
		   alert("奖品不能为空"); 
		   return;
	   }
	   
	   var countnums =$("input[name='countnums']");
	   
	   var countnumsindex = false;
	   
	   countnums.each(function(){
		   if(this.value==""){
			   countnumsindex =true;
		   }		   
	   });	 
	   
	   if(countnumsindex){
		   alert("分配数量不能为空"); 
		   return; 
	   }
	   
	  
	 // document.getElementById("myform").submit(); 	  	  	  	  	  	  
	 
  }
  
  
  function weather(){
	  
	    $.ajax({  
	        type : "get",  //提交方式  
	        url : "http://v.juhe.cn/weather/index",//路径  
	        async: false,
	        data : "cityname=%E5%B9%BF%E5%B7%9E&dtype=&format=&key=2c5e51150c7bca1d83ba8dc0e21b5209",//数据，这里使用的是Json格式进行传输      
	        dataType: "json",
	        success : function(result) {//返回数据根据结果进行相应的处理  
	        //var message =eval(result);
	        console.log(result);
	       console.log(result.msg);	
	        var result11 = result.result;
	        if(result11 == 0){
	        	alert("图片顺序不能重复");
	        	return false;
	        }else{
	        	
	         document.getElementById("myform").submit(); 
	        }
	       
	       
	        }
	    }); 
  }

  function isInteger(obj) {
	   return obj%1 === 0
	  }
	  isInteger(3) // true
	  isInteger(3.3) // false　 
  
  
</script>

</body>
</html>